<?php

namespace App\Http\Requests;
use Illuminate\Validation\Rule;

/**
 * 表单验证
 * Class RoleSaveRequest
 * @package App\Http\Requests
 */
class RoleSaveRequest extends BaseRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->get('id', 0);
        $rules = [
            'name' => [
                'required',
                'between:2,20',
                Rule::unique('roles', 'name')->where('deleted_at', 0)->ignore($id)
            ]
        ];
        return $rules;
    }

    public function messages()
    {
        return [
            'name.required' => '请输入角色名称',
            'name.between' => '角色名称字符长度:min-:max',
            'name.unique' => '角色名称已存在'
        ];
    }
}
